package com.ruoyi.web.core.packet;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;

/**
 * @author: lhl
 * @date: 2021年07月20日 16:20
 */
public class MessagePacket {
    /**
     * 事务处理标识
     **/
    protected byte[] transactionId;

    /**
     * CRC32校验
     **/
    protected byte[] crcCheck;
    /**
     * 数据包
     **/
    protected byte[] body;
    /**
     * 设备时间戳
     */
    private long deviceTimestamp;
    /**
     * 数据包数量
     */
    private int packetNumber;
    /**
     * 16进制字符用于输出
     */
    private String bodyHexStr;

    /**
     * ic卡号
     */
    private int cardNum;

    private LocalDateTime swipeCardDate;

    private boolean flag;


    private List<InsideMessagePacket> insideMessagePacks = new ArrayList<>();


    /**
     * 打印响应
     *
     * @return
     */
    public String responsePacketString() {
        return new StringJoiner(", ", MessagePacket.class.getSimpleName() + "[", "]")
                .add("transactionId=" + Arrays.toString(transactionId))
                .add("crcCheck=" + Arrays.toString(crcCheck))
                .add("deviceTimestamp=" + deviceTimestamp)
                .add("body=" + Arrays.toString(body))
                .add("cardNum='" + cardNum + "'")
                .add("bodyHexStr='" + bodyHexStr + "'")
                .add("swipeCardDate='" + swipeCardDate + "'")
                .add("flag='" + flag + "'")
                .toString();
    }


    @Override
    public String toString() {
        return new StringJoiner(", ", MessagePacket.class.getSimpleName() + "[", "]")
                .add("设备事务标识ID=" + Arrays.toString(transactionId))
                .add("校验码=" + Arrays.toString(crcCheck))
                .add("秒时间戳=" + deviceTimestamp)
                .add("packetNumber=" + packetNumber)
                .add("包体=" + Arrays.toString(body))
                .add("卡号='" + cardNum + "'")
                .add("bodyHexStr='" + bodyHexStr + "'")
                .add("swipeCardDate='" + swipeCardDate + "'")
                .add("数据包=" + Arrays.asList(insideMessagePacks))
                .toString();
    }

    public byte[] getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(byte[] transactionId) {
        this.transactionId = transactionId;
    }

    public byte[] getCrcCheck() {
        return crcCheck;
    }

    public void setCrcCheck(byte[] crcCheck) {
        this.crcCheck = crcCheck;
    }

    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
    }

    public long getDeviceTimestamp() {
        return deviceTimestamp;
    }

    public void setDeviceTimestamp(long deviceTimestamp) {
        this.deviceTimestamp = deviceTimestamp;
    }

    public int getPacketNumber() {
        return packetNumber;
    }

    public void setPacketNumber(int packetNumber) {
        this.packetNumber = packetNumber;
    }

    public String getBodyHexStr() {
        return bodyHexStr;
    }

    public void setBodyHexStr(String bodyHexStr) {
        this.bodyHexStr = bodyHexStr;
    }

    public int getCardNum() {
        return cardNum;
    }

    public void setCardNum(int cardNum) {
        this.cardNum = cardNum;
    }

    public LocalDateTime getSwipeCardDate() {
        return swipeCardDate;
    }

    public void setSwipeCardDate(LocalDateTime swipeCardDate) {
        this.swipeCardDate = swipeCardDate;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public List<InsideMessagePacket> getInsideMessagePacks() {
        return insideMessagePacks;
    }

    public void setInsideMessagePacks(List<InsideMessagePacket> insideMessagePacks) {
        this.insideMessagePacks = insideMessagePacks;
    }
}
